const {
  app,
  BrowserWindow,
  Notification,
  ipcMain,
  dialog
} = require('electron')
let win
app.on('ready', () => {
  win = new BrowserWindow({
    width: 300,
    height: 300,
    webPreferences: {
      nodeIntegration: true,
      contextIsolation: false
    }
  })
  win.loadFile('./index.html')
  handleIPC()
})


function handleIPC() {
  ipcMain.handle('work-notification', async function () {
    
    let res = await new Promise((resolve, reject) => {
      // let notification = new Notification({
      //   title: '任务结束',
      //   body: '是否需要休息',
      //   // actions: [{
      //   //   text: '开始休息',
      //   //   type: 'button'
      //   // }],
      //   // closeButton: '继续工作'
      // });
      // notification.show()
      dialog.showMessageBox({
        type:"info",
        buttons:["开始休息","继续工作"],
        title:"提示：计时结束",
        message:`
        是否需要休息
        `
      }).then((result)=>{
        if(result.response==0){
            resolve('rest')
        }else if(result.response==1){
            resolve('work')
        }
      }).catch((error)=>{
        console.log(error);
      });
    })
    return res;
  })
}